<?php
	if(file_exists("./cms".HOST.".css"))
		$strSiteCSS = "cms".HOST.".css";
	else
		$strSiteCSS = "shop.css";	
?>
<script language="javascript" type="text/javascript" src="/vendere-jscript/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
	theme : "advanced",
	ask : false,
	plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu",
	theme_advanced_buttons1_add_before : "save,separator",
	theme_advanced_buttons1_add : "fontselect,fontsizeselect",
	theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
	theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
	theme_advanced_buttons3_add_before : "tablecontrols,separator",
	theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_path_location : "bottom",
	theme_advanced_resizing : true,
	// Example content CSS (should be your site CSS)
	content_css : "<?php echo $strSiteCSS;?>",
	plugin_insertdate_dateFormat : "%Y-%m-%d",
	plugin_insertdate_timeFormat : "%H:%M:%S",
	extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
	spellchecker_languages : "+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv"
	
});

function toggleEditor(id) {
	var elm = document.getElementById(id);

	if (tinyMCE.getInstanceById(id) == null)
		tinyMCE.execCommand('mceAddControl', false, id);
	else
		tinyMCE.execCommand('mceRemoveControl', false, id);
}

window.onload = toggleEditor('txtEmailContent');

</script>

<?php

$strScreenName = "EmailSelectedCustomers";
$strFormName = "frmEmailCustomer";


	if (!$strSearching)
	{
		$txtFromName = $strCompany;
		$txtReplyEmail = $strMailShotEmail;
		$txtEmailCC = $strMailShotEmail;
		$txtSubject = "Re: ";
		//$txtEmailContent = "<br/>";
	}

echo (StartForm($strScreenName, "post", $strQueryName,array('strSearching'=>"True",'intCustomerID'=>$intCustomerID),"","",$strFormName,""));
if($strStyleSheet == TRUE){
	echo "<table class='Normal' border='0' align='center' width='100%'>";
}
echo "
 <tr>
     <td>
         <table  width='100%' cellpadding='0' cellspacing='0' border='0' class='Normal' align='center'>
		     <tr align='left'>
		         <td align='left' colspan='2'>
		             <h2>Search Customer To Email</h2>
		         </td>
		     </tr>
";
	if(!$intCustomerID){
			echo "
	<tr>
         <td align='right' colspan='1'>
             <b>ID :&nbsp;</b>
         </td>
         <td align='left' colspan='1'>
             <input type=\"text\" name=\"txtID\" value = '$txtID' size= \"4\" maxlength=\"4\">
         </td>
     </tr>
	 <tr>
		<td align=\"right\">
			<b>Valid for (days) :&nbsp;</b>
		</td>
		<td align='left'>";
			CreateDropDown("cboValidFor", "SELECT * FROM tblUserValidity ORDER BY 2", "", $cboValidFor);
			echo 
		"</td>
	</tr>

     <tr align='left'>
         <td align='right'>
             <b>Contact Title :&nbsp;</b><br/>
         </td>
         <td align='left'>";
             CreateDropDown("cboTitle", "SELECT * FROM tblTitle ORDER BY 2", "", $cboTitle);
echo "
         </td>
     </tr>

     <tr>
         <td align='right' colspan='1'>
             <b>First Name :&nbsp;</b>
		</td>
         <td align='left'>
             <input type=\"text\" name=\"txtFirstName\" value = '$txtFirstName' size= \"30\" maxlength=\"40\">
         </td>
     </tr>

     <tr>
         <td align='right' colspan='1'>
             <b>Surname :&nbsp;</b>
         </td>
         <td align='left' colspan='1'>
             <input type=\"text\" name=\"txtSurname\" value = '$txtSurname' size= \"30\" maxlength=\"30\">
         </td>
     </tr>

     <tr>
         <td align='right' colspan='1'>
             <b>Address :&nbsp;</b>
		</td>
         <td align='left'>
             <input type=\"text\" name=\"txtAddress1\" value = '$txtAddress1' size= \"30\" maxlength=\"60\">
         </td>
     </tr>

     <tr>
         <td align='right' colspan='1'>
             &nbsp;
		</td>
         <td align='left'>
             <input type=\"text\" name=\"txtAddress2\" value = '$txtAddress2' size= \"30\" maxlength=\"60\">
         </td>
     </tr>

     <tr>
         <td align='right' colspan='1'>
             <b>City :&nbsp;</b>
         </td>
         <td align='left' colspan='1'>
             <input type=\"text\" name=\"txtCity\" value = '$txtCity' size= \"30\" maxlength=\"30\">
         </td>
     </tr>

     <tr>
         <td align='right' colspan='1'>
             <b>Region :&nbsp;</b>
         </td>
         <td align='left' colspan='1'>
             <input type=\"text\" name=\"txtRegion\" value = '$txtRegion' size= \"25\" maxlength=\"25\">
         </td>
     </tr>

     <tr>
         <td align='right' colspan='1'>
             <b>Postal Code :&nbsp;</b>
         </td>
         <td align='left' colspan='1'>
             <input type=\"text\" name=\"txtPostalCode\" value = '$txtPostalCode' size= \"10\" maxlength=\"10\">
         </td>
     </tr>
		";
	}
echo "
			<tr>
		         <td align='right' colspan='2'>
		             <input type='image' src='./images/search.gif' alt='search'>
		         </td>
		     </tr>

			 <tr>
					<td colspan='2'>
						<hr><b>Email Details</b>
					</td>
			</tr>
			
			<tr>
		         <td align='right' colspan='1'>
				 	<b>From :&nbsp;</b>
				</td>
				<td align='left'>
					<input type=\"text\" name=\"txtFromName\" value = '$txtFromName' size= \"40\" maxlength=\"70\">
				</td>
		
		     </tr>
			 
			 <tr>
			 	<td align='right' colspan='1'>
					<b>Reply Email :&nbsp;</b>
				</td>
				<td align='left'>
					<input type=\"text\" name=\"txtReplyEmail\" value = '$txtReplyEmail' size= \"40\" maxlength=\"70\">
				</td>
			</tr>
			
		
			
			 <tr>
		         <td align='right' colspan='1'>
		             <b>Subject :&nbsp;</b>
		         </td>
		         <td align='left' colspan='1'>
		             <input type=\"text\" name=\"txtSubject\" value = '$txtSubject' size= \"40\" maxlength=\"100\">
		         </td>
		     </tr>
			 
			 <tr>
		         <td align='right' colspan='1'>
		             <b>CC :&nbsp;</b>
		         </td>
		         <td align='left' colspan='1'>
		             <input type=\"text\" name=\"txtEmailCC\" value = '$txtEmailCC' size= \"40\" maxlength=\"100\">
		         </td>
		     </tr>


			<tr>
					<td colspan='2'>
						<a href=\"javascript:toggleEditor('txtEmailContent');\">Add/Remove editor</a><br />
						<textarea cols='60' rows='10' id='txtEmailContent' name='txtEmailContent'>".stripslashes($txtEmailContent)."</textarea>
					</td>
			</tr>
		
				<tr>
					<td colspan='2' align='right'>";

		echo "
					Preview Emails&nbsp;&nbsp;
					<input type='checkbox' name='chkPreview' value='True' ";
						if ($chkPreview == "True"){ echo "checked";}
		echo "
					>&nbsp;&nbsp;|&nbsp;&nbsp;Send Now
					<input type='checkbox' name='chkSendNow' value='True'";
					
						if ($chkSendNow == "True"){ 
							echo "checked";
						}
						
		echo "		
					>
					</td>
				</tr>
		";
		echo "		
		     <tr>
		         <td align='right' colspan='2'>
		             <input type='image' src='./images/submit.gif' alt='submit'>
		         </td>
		     </tr>
		     </form>
         </table>
     </td>
</tr>
 <tr>
     <td>";

	if(($strSearching)||($intCustomerID)){
	
		if($intCustomerID){$txtID=$intCustomerID;}
		
		include (MODULE . "/action/qrySearchCustomer");
		//echo $strSQL;
		do 
		{
			// Add $strHeader
			include (MODULE_LOCAL . "/navigation/EmailHeader");
			
			//include (MODULE_LOCAL . "/navigation/EmailFooter");
			echo "

				<table border='0' align='center' class='Normal'>
					<tr>
						<td width='600'>
							<hr/>"
							.$myrow[Email]."&nbsp;"
		 					.DisplayLookupValue("tblTitle","Title",$myrow[Title])
							."&nbsp;".$myrow[FirstName]."&nbsp;".$myrow[Surname]."&nbsp;
						</td>
					</tr>
				</table>
			";
			$strMessageBody = "	
				<table border='0' align='center' class='Normal'>
					<tr>
						<td align='left' width='600'>
							
							<br/>";
				//if($myrow[FirstName]){
					$strMessageBody .= "<p>Dear ".$myrow[FirstName]."</p>";
				//}
			$strMessageBody .= stripslashes($txtEmailContent)."
						</td>
					</tr>
				</table>
			";
				if ($chkPreview == "True"){
					//echo $strHeader;
					echo "	
						<table border='0' align='center' class='Normal'>
							<tr>
								<td>$strHeader</td>
							</tr>
							<tr>
								<td align='left' width='600'>
									
							<br/><b>To :</b> ".$myrow["Email"]."
							<br/><b>From :</b> $txtFromName ($txtReplyEmail)
							<br/><b>CC :</b> $txtEmailCC
							<br/><b>Subject :</b> $txtSubject";
							
						if($myrow[FirstName]){
							echo "<p>Dear ".$myrow[FirstName]."</p>";
						}
						
					echo "
							
							<p>
									".stripslashes($txtEmailContent)."
									</p><br/><br/><br/>
								</td>
							</tr>
							<tr>
								<td>$strFooter</td>
							</tr>
						</table>
					";
					//echo $strEmailFooter
				}
						
				if ($chkSendNow == "True"){
					SendMime($txtSubject, $strMessageBody,$myrow["Email"], $txtReplyEmail, $txtFromName,$strHeader,$strFooter,$txtEmailCC);
					
					array_push($ActionResults, "Sent ".$myrow["Email"]."Email");
					$strNote = "<br/><b>To :</b> ".$myrow["Email"]."
							<br/><b>From :</b> $txtFromName ($txtReplyEmail)
							<br/><b>CC :</b> $txtEmailCC
							<br/><b>Subject :</b> $txtSubject<br/>$txtEmailContent";
					
					//$strNote = nl2br($strNote);
					$strExtraSQL = "INSERT INTO tblCustomerNotes
                     (     tblCustomerNotes.Customer
                         , tblCustomerNotes.Note
                         , tblCustomerNotes.TimeStamp
                         , tblCustomerNotes.Staff
                         , tblCustomerNotes.UploadedDocument
                     )Values( '".$myrow["ID"]."'
                         , '$strNote'
                         , now()
                         , '".$_SESSION['sesStaffID']."'
                         , 'none'
                     )";
					 include (MODULE . "/action/actMySqlResultsstrRow");
				}
		 } while ($myrow = mysql_fetch_array($result));
	}
	
echo "</td>
</tr>";
	if($strStyleSheet == TRUE){
   		echo "</table>";
	} 
?>
